<template>
  <div class="goods-create">
    <h3>发布商品</h3>
    <el-form :model="form" label-width="120px">
      <el-form-item label="商品名称">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="商品分类">
        <el-select v-model="form.category" placeholder="请选择分类">
          <el-option label="电子产品" value="electronics" />
          <el-option label="服装" value="clothing" />
          <el-option label="食品" value="food" />
        </el-select>
      </el-form-item>
      <el-form-item label="商品价格">
        <el-input-number v-model="form.price" :step="10" />
      </el-form-item>
      <el-form-item label="库存数量">
        <el-input-number v-model="form.stock" />
      </el-form-item>
      <el-form-item label="商品图片">
        <el-upload action="/api/upload" list-type="picture-card" :on-success="handleUploadSuccess">
          <i class="el-icon-plus"></i>
        </el-upload>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitProduct">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

const form = ref({
  name: '',
  category: '',
  price: 0,
  stock: 0,
  images: []
})

const handleUploadSuccess = (response, file) => {
  form.value.images.push(file.url)
}

const submitProduct = () => {
  // 模拟提交逻辑
  console.log('提交商品:', form.value)
  ElMessage.success('商品提交成功')
}
</script>